data_dict={} #agent模式下用户临时存放资产汇报信息
from conf import settings,host_config
import platform,re
class Base(object):
    def __init__(self):
        func=self.get_platform()
        getattr(self,func)()

    def get_platform(self):
        res=None
        os_platform=platform.platform()
        if re.search('windows',os_platform,re.I):
            res='windows'
        elif re.search('linux',os_platform,re.I):
            res='linux'
        else:
            raise Exception('只支持windows与linux-----')
        return res

    def ssh(self,host_dict,command):
        import paramiko
        ssh=paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(host_dict['hostname'],host_dict['port'],host_dict['username'],host_dict['password'])

        stdin,stdout,stderr=ssh.exec_command('ip ad li %s'%settings.manageer_nic_name)
        if stderr.read():
            print('配置文件指定的manageer_nic_name 不存在!')
            return '配置文件指定的manageer_nic_name 不存在!'

        stdin,stdout,stderr=ssh.exec_command(command)
        res=stdout.read()
        ssh.close()
        return res






